<?php
include dirname(dirname(__FILE__)) . '/include/common.php';

class webServiceRegisterRegistrationID extends core {

    public function process() {
        if (!isset($_POST['profileID'])) {
            $this->_response('ERROR::The profile ID is empty');
        }

        $profile_id = intval($_POST['profileID']);
        
        if(!$this->checkProfileID($profile_id)) {
            $this->_response('ERROR::The profile ID is incorrect');
        }
        
        $registrationID = $_POST['registrationID'];
        $device_id = $this->getDeviceIDByProfileID($profile_id);
        if($device_id){
        	$this->db->query("UPDATE devices SET `registration_id` = '{$registrationID}' WHERE device_id = '{$device_id}' LIMIT 1");
        }else{
        	$this->_response('ERROR');
        }
            
        $this->_response(1);
    }

}

$processor = new webServiceRegisterRegistrationID();
$processor->process();
?>